package org.zanateh.wargame.game.util;

import android.util.Pair;

public class Coordinate {
	private final int mRow;
	private final int mCol;
	
	public Coordinate(int pCol, int pRow) {
		mCol = pCol;
		mRow = pRow;
	}
	
	public final int getRow()
	{
		return mRow;
	}

	public final int getCol()
	{
		return mCol;
	}
	
	public boolean isAdjacentTo(Coordinate pCoord) {
			// Coord1 and Coord2 are adjacent if:
			// 1. Their cols are the same and they differ by 1 row
			if( this.mCol == pCoord.mCol) {
				if( Math.abs(pCoord.mRow - this.mRow) == 1 ) return true;
				else return false;
			}

			if( Math.abs(pCoord.mCol - this.mCol) == 1 ) {
			// 2. Their rows are the same and they differ by 1 col
				if( this.mRow == pCoord.mRow) return true;
				
			// 3a. if coord1.col is odd, coord2.col is off by one AND coord2.row is coord1.row+1
				if( this.mCol % 2 == 1 ) {
					if(this.mRow + 1 == pCoord.mRow) return true;
					else return false;
				}
				else {
					// 3b. if coord1.col is even, coord2.col is off by one AND coord2.row is coord1.row-1
					if(this.mRow - 1 == pCoord.mRow) return true;
					else return false;
				}
			}
			else return false;
	}
	
}
